from base.vertice import Vertice
from base.graph import Graph
from dijkstra import dijkstra

w = dict()  # dicionario dos pesos das arestas, associa um peso a cada aresta!


def weight(pair):
    if pair in w:
        return w[pair]

vertices = [Vertice(0), Vertice(1), Vertice(2), Vertice(3), Vertice(4)]
g = Graph(vertices)

# Adjacencias Vertice 0:

g.add_edge(vertices[0], vertices[1])
w[(vertices[0], vertices[1])] = 1

g.add_edge(vertices[0], vertices[3])
w[(vertices[0], vertices[3])] = 3

g.add_edge(vertices[0], vertices[4])
w[(vertices[0], vertices[4])] = 10

# Adjacencias Vertice 1:

g.add_edge(vertices[1], vertices[2])
w[(vertices[1], vertices[2])] = 5

# Adjacencias Vertice 2:

g.add_edge(vertices[2], vertices[4])
w[(vertices[2], vertices[4])] = 1

# Adjacencias Vertice 3:

g.add_edge(vertices[3], vertices[4])
w[(vertices[3], vertices[4])] = 6

g.add_edge(vertices[3], vertices[2])
w[(vertices[3], vertices[2])] = 2

result_set = dijkstra(g, weight, vertices[0])

print('Menor caminho usando dijkstra entre a entrada e a saída da linha de produção: ')

path = ''
    
for v in result_set[vertices[4]][::-1]:
    path += str(v.name) + ', '

print(path)

print('Custo: %.2f' %vertices[4].key)